package com.lianzhihui.romeex.widget.dialog;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.lianzhihui.romeex.inter.CustomCallback;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.ui.base.BaseDialog;
import com.makeramen.roundedimageview.RoundedImageView;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * ProjectName:    NBN
 * ClassName:      CreateNidDialog
 * Description:    创建NID
 * Author:         echo
 * CreateDate:     2019/11/7 14:42
 * UpdateUser:     更新者
 * UpdateDate:     2019/11/7 14:42
 * UpdateRemark:   更新说明
 * Version:        1.0
 */
public class CustomConfirmDialog extends BaseDialog {
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.tv_describe)
    TextView tv_describe;
    @BindView(R.id.bt_compare)
    Button bt_compare;
    @BindView(R.id.iv_icon)
    RoundedImageView iv_icon;
    @BindView(R.id.ll_content_text)
    View ll_content_text;
    @BindView(R.id.iv_content_image)
    ImageView iv_content_image;
    @BindView(R.id.iv_close)
    ImageView iv_close;
    @BindView(R.id.bt_jump)
    TextView bt_jump;
    private boolean showClose;
    private CustomCallback customCallback;
    public CustomConfirmDialog(@NonNull Activity activity) {
        super(activity);
    }

    @Override
    protected int provideViewId() {
        return R.layout.dialog_custom;
    }
    public void setTitle(String title){
        tv_title.setText(title);
    }
    public void setButton(String title){
        bt_compare.setText(title);
    }
    public void setButtonJump(String title){
        if (!TextUtils.isEmpty(title)){
            bt_jump.setVisibility(View.VISIBLE);
            bt_jump.setText(title);
        }else {
            bt_jump.setVisibility(View.GONE);
        }
    }
    public void setIcon(String iconUrl){
        if (!TextUtils.isEmpty(iconUrl)) {
            iv_icon.setVisibility(View.VISIBLE);
            Glide.with(getContext()).load(iconUrl).into(iv_icon);
            Glide.with(getContext()).load(iconUrl).into(iv_content_image);
        }
    }
    public void setDescribe(String describe){
        tv_describe.setText(describe);
    }
    public void setCustomCallback(CustomCallback customCallback){
        this.customCallback = customCallback;
    }
    public void showClose(boolean showClose){
        this.showClose = showClose;
        if (showClose) {
            iv_close.setVisibility(View.VISIBLE);
        }
    }
    @Override
    protected void initView() {
    }

    @OnClick({R.id.bt_compare,R.id.iv_content_image,R.id.bt_jump,R.id.iv_close})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.bt_compare:
                if (showClose){
                    customCallback.onCompare("");
                }else {
                    if (customCallback!=null) {
                        customCallback.onCompare("jump");
                    }
                    dismiss();
                }
                break;
            case R.id.iv_content_image:
                customCallback.onCompare("");
                break;
            case R.id.bt_jump:
            case R.id.iv_close:
                dismiss();
                break;
        }
    }
}
